<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <input type="text" id="clock" />
    <button onclick="stopClock()">停止</button>

    <input type="text" id="stopwatch" />
    <button onclick="stopWatch()">一次性秒表</button>


    <script>
        // 
        let timer = setInterval(function(){
            startClock();
        }, 1000);
        // start
        function startClock(){
            let clock = document.querySelector("#clock");
            let nowDate = new Date();
            let nowTime = nowDate.toLocaleTimeString();
            clock.value = nowTime;
        }
        // stop
        function stopClock(){
            // 清除代码
            clearInterval(timer);
            timer = null;
        }
        // stopWatch
        function stopWatch(){
            setTimeout(function(){
                document.querySelector("#stopwatch").value = "3秒倒计时结束";
            }, 3000);
        }

    </script>

</body>
</html>